package com.naiterui.common.jinshuju.constants;

import java.util.Arrays;

import lombok.Getter;

/**
 * 金数据表单业务常量
 */
public class JinshujuConstants {

    /**
     * 金数据透传字段标识
     */
    public static final String JINSHUJU_EXTRA_KEY = "x_field_1";
    public static final String JINSHUJU_ENTRY_KEY = "field_";
    /**
     * 金数据微信相关字段标识
     */
    public static final String JINSHUJU_WX_OPENID_KEY = "x_field_weixin_openid";
    public static final String JINSHUJU_WX_NICKNAME_KEY = "x_field_weixin_nickname";
    public static final String JINSHUJU_WX_ENDER_KEY = "x_field_weixin_gender";
    public static final String JINSHUJU_WX_COUNTRY_KEY = "x_field_weixin_country";
    public static final String JINSHUJU_WX_PROVINCECYTI_KEY = "x_field_weixin_province_city";
    public static final String JINSHUJU_WX_HEADIMGURL_KEY = "x_field_weixin_headimgurl";
    /**
     * 金数据表单结构缓存前缀
     */
    public static final String JINSHUJU_FORMCACHE_PREFIX = "jinshuju|form_";
    /**
     * 金数据Base
     */
    public static final String DEFAULT_CHARSET = "UTF-8";
    public static final String SERIAL_NUMBER_KEY = "serial_number";

    @Getter
    public enum QuestType {
        //问题类型:1.单选框，2.复选框，3.下拉框，4.日期，5.Email，6.数字，7.电话，8.多行文本，9.单行文本
        single_choice(1, "单选框"),
        multiple_choice(2, "复选框"),
        drop_down(3, "下拉框"),
        date(4, "日期"),
        email(5, "邮箱"),
        number(6, "数字"),
        phone(7, "电话"),
        paragraph_text(8, "多行文本"),
        single_line_text(9, "单行文本"),
        formula(10, "计算字段"),
        other(99, "其他（金数据API暂不支持此类表单项）");

        private int type;
        private String typeDesc;

        QuestType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public static QuestType byTypeStr(String typeStr) {
            return Arrays.stream(QuestType.values()).filter(o -> o.name().equalsIgnoreCase(typeStr)).findFirst().orElse(other);
        }
    }
}
